#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 7;

struct cow {
  int x, y;
  bool operator<(const cow& a) const { return y < a.y; }
} c[N];
int n, sb[N], xb[N];
#define lowbit(x) (x & -x)
void change(int a[], int x, int k) {
  while (x <= n) {
    a[x] += k, x += lowbit(x);
  }
}
int query(int a[], int x) {
  int res = 0;
  while (x > 0) {
    res += a[x], x -= lowbit(x);
  }
  return res;
}
bool check(int x) {
  memset(sb, 0, sizeof(sb));
  memset(xb, 0, sizeof(xb));
  for (int i = 1; i <= n; ++i) change(sb, c[i].x, 1);
  int st = n, xt = 0, zs = 1, zx = n;
  for (int t, i = 1, j = 1; i <= n; i = j) {
    while (c[i].y == c[j].y) {
      change(sb, c[j].x, -1);
      change(xb, c[j].x, 1);
      st--, xt++, j++;
    }
    while (zs <= n && query(sb, zs) <= x) {
      zs++;
    }
    zs--;
    while (zs > 0 && query(xb, zx) > x) {
      zx--;
    }
    t = min(zx, zs);
    if (xt - query(xb, t) <= x && st - query(sb, t) <= x) {
      return true;
    }
  }
  return false;
}
pair<int, int> p[N];
int tot, mid, l, r, ans;
int main() {
  cin >> n;
  for (int i = 1; i <= n; ++i) {
    cin >> c[i].x >> c[i].y;
    p[i].first = c[i].x, p[i].second = i;
  }
  sort(p + 1, p + n + 1);
  for (int i = 1; i <= n; ++i) {
    if (p[i].first != p[i - 1].first) {
      tot++;
    }
    c[p[i].second].x = tot;
  }
  sort(c + 1, c + n + 1);
  l = 1, r = n;
  while (l <= r) {
    mid = (l + r) / 2;
    if (check(mid)) {
      r = mid - 1;
      ans = mid;
    } else {
      l = mid + 1;
    }
  }
  cout << ans << endl;
  return 0;
}
